package day10.download;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("127.0.0.1", 6666);

        try(
                InputStream is = new FileInputStream("src\\main\\resources\\a.wma");
                OutputStream os = s.getOutputStream();
                ){
            int len = 0;
            byte[] b = new byte[1024];
            while ((len = is.read(b)) > 0) {
                os.write(b, 0, len);
            }

            //写个-1到客户端
            s.shutdownInput();

            InputStream is2 = s.getInputStream();
            int len2 = 0;
            byte[] b2 = new byte[1024];
            while ((len2 = is2.read(b2)) > 0) {
                System.out.println(new String(b2, 0, len2));
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        s.close();
    }
}
